<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use dosamigos\datetimepicker\DateTimePicker;
use yii\grid\GridView;
use yii\widgets\Pjax;
use backend\models\StatisticSearch;

$this->title = '商品订单统计';
$this->params['breadcrumbs'][] = $this->title;
?>
<style>

</style>
<div class="statistic-search">

    <div class="box box-success">
        <div class="box-body">
         <?php
            \Yii::$container->set(\yii\widgets\ActiveField::className(), ['template' => "{label}\n{input}\n{hint}"]);
            $form = ActiveForm::begin([
            'action' => ['index'],
            'method' => 'get',
            'options'=> ['class' => 'form-inline'],
            ]); ?>
            <?= $form->field($searchModel, 'start_time')->widget(DateTimePicker::className(),
                [
                    'template'=>"{input}{reset}{button}",
                    'clientOptions' => [
                        'autoclose' => true,
                        'linkFormat' => 'yyyy-MM-dd', // if inline = true
                        //'format' => 'yyyy-mm-dd', // if inline = false
                        'todayBtn' => true,
                        'pickerPosition'=>"bottom-left",
                        'language'=>'zh-CN',
                        'minView'=>'hour'
                    ]
                ])?>

            <?= $form->field($searchModel, 'end_time')->widget(DateTimePicker::className(),
                [
                    'template'=>"{input}{reset}{button}",
                    'clientOptions' => [
                        'autoclose' => true,
                        'linkFormat' => 'yyyy-MM-dd', // if inline = true
                        //'format' => 'yyyy-mm-dd', // if inline = false
                        'todayBtn' => true,
                        'pickerPosition'=>"bottom-left",
                        'language'=>'zh-CN',
                        'minView'=>'hour'
                    ]
                ])?>
            <div class="form-group">
                <?= Html::submitButton('搜索', ['class' => 'btn btn-primary']) ?>
                <?= Html::label('导出','', ['class' => 'exportButton btn btn-primary']) ?>
            </div>
            <?php ActiveForm::end(); ?>
        </div>
    </div>
    <div class="box box-success">
        <div class="box-body">
            <?php Pjax::begin(); ?>
            <?= GridView::widget([
        'dataProvider' => $dataInfo,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'goods_id',
            'product_id',
            ['label'=>'商品规格', 'value' =>
                function ($data) {
                    return isset($data->product_id) ? StatisticSearch::specInfo($data->product_id) : '未设置' ;
                }
            ],
            ['label'=>'客户',   'value' =>
                function ($data) {
                    return isset($data->goodsDetail->goods_supply_id) ? StatisticSearch::GSupplier($data->goodsDetail->goods_supply_id) : '未设置' ;
                }
            ],
            ['label'=>'是否售卖',   'value' =>
                function ($data) {
                    $info = StatisticSearch::productInfo($data->product_id);
                    return (isset($info['type']) && 1==$info['type'])? '是':'否';
                }
            ],
            ['label'=>'是否试用',   'value' =>
                function ($data) {
                    $info = StatisticSearch::productInfo($data->product_id);
                    return (isset($info['type']) && 2==$info['type'])? '是':'否';
                }
            ],
            ['label'=>'售卖价格',   'value' =>
                function ($data) {
                    $info = StatisticSearch::productInfo($data->product_id);
                    return (isset($info['sale_price']))?$info['sale_price']:'0.00';
                }
            ],
            ['label'=>'试用价格',   'value' =>
                function ($data) {
                    $info = StatisticSearch::productInfo($data->product_id);
                    return (isset($info['try_price']))?$info['try_price']:'0.00';
                }
            ],
            'buy_number',

        ],
    ]); ?>
            <?php Pjax::end(); ?>
        </div>
     </div>
</div>
<?php $this->beginBlock('js');?>
<script type="text/javascript">
    $(function(){
        $('.exportButton').click(function(){
            startime=$('#statisticsearch-start_time').val();
            endtime =$('#statisticsearch-end_time').val();
            url      ="<?=Yii::$app->urlManager->createUrl([Yii::$app->controller->id .'/explort','start_time'=>''])?>"+startime+'&end_time'+endtime;
            window.location.href = url;

        });
    })
</script>
<?php $this->endBlock();?>